<?php
/**
 * CreateTime: 2022/5/16 11:46
 */

namespace App\ServiceChecker\Contract;

use App\Consts\BaseConsts\BaseConsts;
use App\Consts\ResponseConsts\ResponseStatusConsts;
use App\Func\ResponseFunc;
use App\Models\Contract\ContractTypeModel;
use App\Models\Department\DepartmentModel;
use App\ServiceChecker\BasicServiceChecker;
use Illuminate\Http\Exceptions\HttpResponseException;

class ContractTypeLegitimacy  extends BasicServiceChecker
{
    private ContractTypeModel $_contractType;

    public function __construct()
    {
        parent::__construct();
        $this->_contractType = new ContractTypeModel();
    }

    public function verifyCompanyCodeIsExists($contractType,$companyId){
        $isExist = $this->_contractType->isExistByCondition([
            'contract_type_code' => $contractType,
            'company_id' => $companyId,
            'status' => BaseConsts::STATUS_NORMAL
        ]);
        if($isExist){
            throw new HttpResponseException( ResponseFunc::returnJson(
                'error',
                null,
                '合同编号已存在',
                ResponseStatusConsts::OK_200_RESPONSE_STATUS,
            ));
        }
    }

    public function verifyContractTypeIsExists($contractTypeName,$companyId){
        $isExist = $this->_contractType->isExistByCondition([
            'contract_type_name' => $contractTypeName,
            'company_id' => $companyId,
            'status' => BaseConsts::STATUS_NORMAL
        ]);
        if($isExist){
            throw new HttpResponseException(ResponseFunc::returnJson(
                'error',
                null,
                '当前合同类型已存在',
                ResponseStatusConsts::OK_200_RESPONSE_STATUS,

            ));
        }
    }


}